package com.dynamixsoftware.printershare.bjnp;

import java.io.IOException;
import java.io.InputStream;

public class BJNPCommand {
	public byte cmd_code;
	public byte[] data;
	public byte dev_type;
	public int dlen = -1;
	public int error_code;
	public int seq_no = 1;
	public int session_id;

	public static BJNPCommand fromPacket(byte[] paramArrayOfByte, int paramInt) {
		if ((paramArrayOfByte[paramInt] == 66) && (paramArrayOfByte[(paramInt + 1)] == 74)
				&& (paramArrayOfByte[(paramInt + 2)] == 78) && (paramArrayOfByte[(paramInt + 3)] == 80)) {
			BJNPCommand localBJNPCommand = new BJNPCommand();
			localBJNPCommand.dev_type = paramArrayOfByte[(paramInt + 4)];
			localBJNPCommand.cmd_code = paramArrayOfByte[(paramInt + 5)];
			localBJNPCommand.error_code = (((0xFF & paramArrayOfByte[(paramInt + 6)]) << 8) + (0xFF & paramArrayOfByte[(paramInt + 7)]));
			localBJNPCommand.seq_no = (((0xFF & paramArrayOfByte[(paramInt + 8)]) << 8) + (0xFF & paramArrayOfByte[(paramInt + 9)]));
			localBJNPCommand.session_id = (((0xFF & paramArrayOfByte[(paramInt + 10)]) << 8) + (0xFF & paramArrayOfByte[(paramInt + 11)]));
			localBJNPCommand.dlen = (((0xFF & paramArrayOfByte[(paramInt + 12)]) << 24)
					+ ((0xFF & paramArrayOfByte[(paramInt + 13)]) << 16)
					+ ((0xFF & paramArrayOfByte[(paramInt + 14)]) << 8) + (0xFF & paramArrayOfByte[(paramInt + 15)]));
			if (localBJNPCommand.dlen > 0) {
				localBJNPCommand.data = new byte[localBJNPCommand.dlen];
				System.arraycopy(paramArrayOfByte, paramInt + 16, localBJNPCommand.data, 0, localBJNPCommand.dlen);
				return localBJNPCommand;
			}
			localBJNPCommand.data = null;
			return localBJNPCommand;
		}
		return null;
	}

	public static BJNPCommand fromStream(InputStream paramInputStream) throws IOException {
		if ((paramInputStream.read() == 66) && (paramInputStream.read() == 74) && (paramInputStream.read() == 78)
				&& (paramInputStream.read() == 80)) {
			byte[] arrayOfByte = new byte[16];
			int i = 4;
			while (i < arrayOfByte.length) {
				int m = paramInputStream.read(arrayOfByte, i, arrayOfByte.length - i);
				if (m == -1) {
					throw new IOException("Unexpected end of stream");
				}
				i += m;
			}
			BJNPCommand localBJNPCommand = new BJNPCommand();
			localBJNPCommand.dev_type = arrayOfByte[4];
			localBJNPCommand.cmd_code = arrayOfByte[5];
			localBJNPCommand.error_code = (((0xFF & arrayOfByte[6]) << 8) + (0xFF & arrayOfByte[7]));
			localBJNPCommand.seq_no = (((0xFF & arrayOfByte[8]) << 8) + (0xFF & arrayOfByte[9]));
			localBJNPCommand.session_id = (((0xFF & arrayOfByte[10]) << 8) + (0xFF & arrayOfByte[11]));
			localBJNPCommand.dlen = (((0xFF & arrayOfByte[12]) << 24) + ((0xFF & arrayOfByte[13]) << 16)
					+ ((0xFF & arrayOfByte[14]) << 8) + (0xFF & arrayOfByte[15]));
			if (localBJNPCommand.dlen > 0) {
				localBJNPCommand.data = new byte[localBJNPCommand.dlen];
				int j = 0;
				while (j < localBJNPCommand.data.length) {
					int k = paramInputStream.read(localBJNPCommand.data, j, localBJNPCommand.data.length - j);
					if (k == -1) {
						throw new IOException("Unexpected end of stream");
					}
					j += k;
				}
			}
			localBJNPCommand.data = null;
			return localBJNPCommand;
		}
		return null;
	}

	public byte[] toPacket() {
		if (this.dlen == -1) {
			int var2;
			if (this.data != null) {
				var2 = this.data.length;
			} else {
				var2 = 0;
			}

			this.dlen = var2;
		}

		byte[] var1 = new byte[16 + this.dlen];
		var1[0] = 66;
		var1[1] = 74;
		var1[2] = 78;
		var1[3] = 80;
		var1[4] = this.dev_type;
		var1[5] = this.cmd_code;
		var1[6] = (byte) (255 & this.error_code >> 8);
		var1[7] = (byte) (255 & this.error_code);
		var1[8] = (byte) (255 & this.seq_no >> 8);
		var1[9] = (byte) (255 & this.seq_no);
		var1[10] = (byte) (255 & this.session_id >> 8);
		var1[11] = (byte) (255 & this.session_id);
		var1[12] = (byte) (255 & this.dlen >> 24);
		var1[13] = (byte) (255 & this.dlen >> 16);
		var1[14] = (byte) (255 & this.dlen >> 8);
		var1[15] = (byte) (255 & this.dlen);
		if (this.dlen > 0) {
			System.arraycopy(this.data, 0, var1, 16, this.dlen);
		}

		return var1;
	}
}

/*
 * Location:
 * C:\Users\Admin\Desktop\Decompiler\JAD\jd-gui-0.3.6.windows\classes_dex2jar
 * .jar
 * 
 * Qualified Name: com.dynamixsoftware.printershare.bjnp.BJNPCommand
 * 
 * JD-Core Version: 0.7.0.1
 */